import Vue, { computed } from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: () => import('../index/layout.vue'),
    children: [
      {
        path: '/',
        component: () => import('../index/index.vue')
      }, {
        path: '/libraryList/:id',
        component: () => import('../library-list/index.vue')
      },
      {
        path: '/seat/:id',
        component: () => import('../seat/index.vue')
      },
      {
        path: '/seminar/:id',
        component: () => import('../seminar/index.vue')
      },
      {
        path: '/personal',
        component: () => import('../personal/index.vue')
      }
    ]
  },
  {
    path: '/seatSign',
    component: () => import('../seat-sign/index.vue')
  },
  {
    path: '/login',
    component: () => import('../Guide/Login'),
  },
  {
    path: '/register',
    component: () => import('../Guide/Register'),
  },
  {
    path: '/admin',
    component: () => import('../admin/Main'),
    children: [
      {
        path: 'announce',
        component: () => import('../admin/announcement/index.vue'),
      },
      {
        path: 'activity',
        component: () => import('../admin/activity/index.vue')
      },
      {
        path: 'forum',
        component: () => import('../admin/ForumManagement'),
      },
      {
        path: 'seat',
        component: () => import('../admin/SeatManagement'),
        children: [
          {
            path: 'number',
            component: () => import('../admin/SeatNumber'),
          },
          {
            path: 'crud',
            component: () => import('../admin/SeatCrud'),
          },
        ],
      },
      {
        path: 'role',
        component: () => import('../admin/role/index.vue')
      },
      {
        path: 'library',
        component: () => import('../admin/library/index.vue')
      },
      {
        path: 'floor',
        component: () => import('../admin/floor/index.vue')
      },
      {
        path: 'readingRoom',
        component: () => import('../admin/readingRoom/index.vue')
      },
      {
        path: 'seminarRoom',
        component: () => import('../admin/seminarRoom/index.vue')
      },
      {
        path: 'user',
        component: () => import('../admin/StudentManagement'),
      }, {
        path: 'booking',
        component: () => import('../admin/booking/index.vue'),
      },
      // {
      //   path: 'teacher',
      //   component: () => import('../admin/TeacherManagement'),
      // },
      {
        path: 'statistics',
        component: () => import('../admin/Statistics'),
      },
    ],
  },
  {
    path: '/student',
    component: () => import('../user/Main'),
    children: [
      {
        path: 'forum',
        component: () => import('../user/Forum'),
      },
      {
        path: 'seat',
        component: () => import('../user/Seat'),
        children: [
          {
            path: 'reservation',
            component: () => import('../user/Reservation'),
          },
          {
            path: 'toSigned',
            component: () => import('../user/ToSigned'),
          },
          {
            path: 'beUse',
            component: () => import('../user/BeUse'),
          },
        ],
      },
    ],
  },
  {
    path: '/LookStudentMess',
    component: () => import('../teacher/StudentMess'),
  },
  {
    path: '/ScoreMess',
    component: () => import('../user/ScoreMess'),
  },
  {
    path: '/PushArticle',
    component: () => import('../user/PushArticle'),
  },
  {
    path: '/ForumInfo',
    component: () => import('../user/ForumInfo'),
  },
  {
    path: '/Teacher',
    component: () => import('../teacher/Main'),
    children: [
      {
        path: 'seat',
        component: () => import('../teacher/SeatMess'),
      },
      {
        path: 'reservation',
        component: () => import('../teacher/ReservationMess'),
      },
      {
        path: 'score',
        component: () => import('../teacher/ScoreManagement'),
      },
    ],
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
})

router.beforeEach((to, from, next) => {
  if (to.path.includes('/admin')) {
    const user = sessionStorage.getItem('admin')
    if (user) {
      next()
    } else {
      next({ path: '/login' })
    }
  } else {
    next()
  }
})

export default router
